//
//  GMBaseTableViewController.m
//  gentleman
//
//  Created by 范月成 on 2017/12/5.
//  Copyright © 2017年 fancy. All rights reserved.
//

#import "GMBaseTableViewController.h"

@interface GMBaseTableViewController ()

@property (nonatomic, strong, readwrite) UITableView *tableView;

@end

@implementation GMBaseTableViewController

- (instancetype)initWithStyle:(UITableViewStyle)style {
    if (self = [super initWithNibName:nil bundle:nil]) {
        [self didInitializedWithStyle:style];
    }
    return self;
}

- (instancetype)init {
    return [self initWithStyle:UITableViewStylePlain];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    return [self init];
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
        [self didInitializedWithStyle:UITableViewStylePlain];
    }
    return self;
}

- (void)didInitializedWithStyle:(UITableViewStyle)style {
    _style = style;
}

- (void)dealloc {
    // 用下划线而不是self.xxx来访问tableView，避免dealloc时self.view尚未被加载，此时调用self.tableView反而会触发loadView
    _tableView.delegate = nil;
    _tableView.dataSource = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)initSubviews {
    [super initSubviews];
    [self initTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

    DEBUGLog(@"%@_didReceiveMemoryWarning", self.class);
    [[SDImageCache sharedImageCache] clearMemory];
}

#pragma mark - Tableview
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return nil;
}

@end

@implementation GMBaseTableViewController (GMSubclassingHooks)

- (void)initTableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:self.style];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView disabledEstimatedHeight];
        [self.view addSubview:self.tableView];
    }
}

@end
